/*----------------------------------------\ | Check the existence of a global macro variable; | |-------------------------------------------| |--------------------------------------------------------------------| |---------------------------| | Parameters: (!=required) | | NAME: name of the macro variable; | | return: if you want to return value (to assign to another var); | | F - no return value; | | T - return a value; | |--------------------------------------| |--------------------------------------------------------------------| |---------------------------------------| | Example (check if &a exists | | %macrovarchk(a) | | %MacroVarChk(%nrstr(&hascolor)); | | %let rc=%MacroVarChk(%nrstr(&hascolor), return=T); | | RESULT in the log window: hascolor Exist: No; | | rc=1 | | Usage: %MacroVarChk(name,return=F); | \-------------------------------------------------------------------*/ %MACRO MacroVarChk(name); /*--------------------------------------------\ | Copy Right: Duo Zhou; | | Created: 9-28-2001 8:38pm; | | Purpose: Check the existence of a global | | macro variable; | \--------------------------------------------*/ %local rc; %let Name=%sysfunc(dequote(&&Name)); %if (%index(&&Name,%str(&))) %then %let Name=%sysfunc(compress(&&Name, %str(&))); %if (%nrquote(&&&name)=%nrstr(&)&name) %then %do; %let yesno=NO; %let rc=0; %end; %else %do; %let yesno=YES; %let rc=1; %end; &rc %MEND MacroVarChk;